<template>
	<view>

		<view class="cu-list menu-avatar">
			<view class="cu-item" @click="login">
				<view class="cu-avatar round lg" :style="'background-image:url('+user_info.avatarUrl+');'"></view>
				<view class="content">
					<view class="text-grey">{{user_info.user_id?user_info.nickname:'登录/注册'}} </view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">

							{{user_info.phone?user_info.phone:'未填手机号'}}
						</view>
					</view>
				</view>

			</view>

			<view class="cu-list menu sm-border margin-top">
				<view class="cu-item arrow" @click="jump('/pages/bills/bills')">
					<view class="content">
						<text class="cuIcon-edit text-red"></text>
						<text class="text-red">我的预约</text>
					</view>
				</view>
			</view>

			<view class="cu-list menu sm-border margin-top">



				<view class="cu-item arrow" @click="login">
					<view class="content">
						<text class="cuIcon-phone text-gray"></text>
						<text class="text-grey">绑定/更新手机号</text>
					</view>
				</view>

				<view class="cu-item arrow" @click="openurl('/pages/post/joinhands')">
					<view class="content">
						<text class="cuIcon-service text-gray"></text>
						<text class="text-grey">联系我们</text>
					</view>
				</view>

				<!-- <view class="cu-item arrow">
					<view class="content">
						<text class="cuIcon-calendar text-gray"></text>
						<text class="text-grey">关于我们</text>
					</view>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import beeApp from '../../beeApp.js'
	export default {
		data() {
			return {
				items: {},
				user_info: {
					tenement_type: [],
					community: {

					}
				},
				noneRoomsList: 0,
				hotline: '',
				user_id: 0,
				roomsList: [],
				userStatistics: {},
				mounted: 0,
				out_room_id: 0,
				community_id: 0,
			}
		},
		onLoad() {
			this.fetchData();
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
		},
		onPullDownRefresh() {
			this.fetchData();
			uni.stopPullDownRefresh();
		},

		onShow: function() {
			var reload = beeApp.getPageData('pages/user/index', 'reload');
			if (reload == 1) {
				beeApp.setPageData('pages/user/index', {
					reload: 0
				});
				this.fetchData();
			}

			// var user_info = uni.getStorageSync("user_info");
			// if(!user_info){
			// 	uni.reLaunch({
			// 		url: '/pages/user/bindphone?page=auth',
			// 		complete: function(res) {
			// 			console.log(res);
			// 		}
			// 	})
			// }
		},

		methods: {
			login() {
				if (this.user_info.user_id) {
					this.bindPhone();
				} else {
					// #ifdef MP-WEIXIN
					beeApp.wxGetUserInfo();
					// #endif
					// #ifdef MP-ALIPAY
					beeApp.aliGetUserInfo();
					// #endif
				}


			},
			jump(url) {
				if (!this.user_info.user_id) {
					this.login();
					return;
				}
				uni.navigateTo({
					url: url
				})
			},
			openurl(url, type) {
				if (type == "switchTab") {
					uni.switchTab({
						url: url
					})
				} else {
					uni.navigateTo({
						url: url
					})
				}

			},
			contactUs: function() {
				uni.makePhoneCall({
					phoneNumber: this.hotline
				});
			},
			pay(item) {
				uni.navigateTo({
					url: "/pages/bills/bills?out_room_id=" + item.out_room_id + "&community_id=" + item.community_id,
				})
			},

			bindPhone: function() {
				// #ifdef MP-WEIXIN
				uni.navigateTo({
					url: '/pages/user/wxbindphone'
				})
				// #endif
				// #ifdef H5
				uni.navigateTo({
					url: '/pages/user/bindphone'
				})
				// #endif

			},
			fetchData: function fetchData() {
				var _this = this;
				this.getUserInfo();
				// _this.user_info = beeApp.getUserInfo();
			},

			getUserInfo: function() {
				var that = this;
				beeApp.api("/api/user/info", {
					store_id: -1,
					fields: "user_id,store_id,phone,nickname,phone,avatarUrl,last_update_time,community,community.bills_count,topic_count,waitingpay,tenement_type,community_count,out_room_id"
				}, function(res) {
					if (res.code == 200) {
						that.user_info = res.data;
						// that.out_room_id = res.data.out_room_id;

					}

				});
			}

		}
	}
</script>

<style>
	.cu-list.menu>.cu-item .content .png {
		width: 40upx;
		height: 40upx;
	}
</style>
